In this chapter we’re going to consider the geometry of models with multiple continuous predictors. We’re also going to talk about the predictive accuracy of our models, which can help us understand how well our models represent our data.
We’re still load and set up the data below:
# data setup
#################################################
# source data
url1 = "https://raw.githubusercontent.com/santiagobarreda"
url2 = "/stats-class/master/data/h95_experiment_data.csv"
h95 = read.csv (url(paste0 (url1, url2)))
# set up colors for plotting
devtools::source_url (paste0 (url1, "/stats-class/master/data/colors.R"))
# source functions
devtools::source_url (paste0 (url1, "/stats-class/master/data/functions.R"))
# padult = 1 for adult responses, 0 for child responses
h95$padult = as.numeric (h95$pgroup %in% c('w','m'))
# factor with f for female responses and m for male responses
h95$pfemale = ""
h95$pfemale[h95$pgroup %in% c('w','g')] = "f"
h95$pfemale[h95$pgroup %in% c('m','b')] = "m"
h95$pfemale = factor(h95$pfemale)
# standardize log f0
h95$gbar_s = (h95$g0-mean(h95$g0)) / sd(h95$g0)
# standardize log geometric mean formant frequency
h95$gbar_s = (h95$gbar-mean(h95$gbar)) / sd(h95$gbar)
We’re going to consider two parallel models predicting height and adultness from speech acoustics. The models include the following dependent variables:
padult: a dichotomous variable, 1=adult response, 0=child response.
pheight: a continuous variable indicatying perceived height in inches.
And the following predictor variables:
g0_s: a continuous predictor, scaled log-f0.
gbar_s: a continuous predictor, scaled log-mean formant frequency (a measure of vocal-tract length).
pfemale: a factor indicating whether subjects indicated hearing a female speaker, pfemale1=female, -pfemale1=female.
vowel: a factor with two levels, vowel1=a, -vowel1=i.
subj: a factor indicating subject/listener (n=10).
speaker: a factor indicating speaker (n=139).
We’re going to begin be talking about the prediction of perceived height using two continuous
(left) . (mid-left) . (mid-right) . (right) .
library (plotly)
## Loading required package: ggplot2
##
## Attaching package: 'ggplot2'
## The following object is masked _by_ '.GlobalEnv':
##
## %+%
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
(left) . (mid-left) . (mid-right) . (right) .
fixef (normal_g0_gbar)
n=100
x = seq (min(agg_data$g0_s),max(agg_data$g0_s), length.out=n)
y = seq (min(agg_data$gbar_s),max(agg_data$gbar_s), length.out=n)
z0 = seq (0,1,length.out=n)
xx = rep (x, each = n)
yy = rep (y, n)
z = 62 - 2.5*xx - 6.4*yy
zz = matrix (z,n,n)
fig2 <- plot_ly(agg_data, x = ~g0_s, y = ~gbar_s, z = ~pheight,
color = ~group, colors = c(coral,skyblue,teal,yellow))
fig2 <- fig2 %>% add_markers()
fig2 <- fig2 %>% layout(scene =
list(aspectmode='cube',
xaxis = list(title = 'log f0'),
yaxis = list(title = 'log mean FF'),
zaxis = list(title = 'Perceived Height (inches)')))
fig2 <- fig2 %>% add_surface (x=x,y=y,z = zz, showscale = FALSE, colorscale = "Jet")
#fig2 <- fig2 %>% layout(showlegend = FALSE)
fig2
fig2 <- plot_ly(agg_data, x = ~g0_s, y = ~gbar_s, z = ~pheight, color = ~group, colors = c(coral,skyblue,teal,yellow))
fig2 <- fig2 %>% add_markers() fig2 <- fig2 %>% layout(scene = list(aspectmode=‘cube’, xaxis = list(title = ‘log f0’), yaxis = list(title = ‘log mean FF’), zaxis = list(title = ‘Perceived Height (inches)’)))
(left) . (mid-left) . (mid-right) . (right) .
The model was described and fit at the end of chapter 8. You can load the model (after downloading it and placing in in your working directory) using the line below:
logistic_g0_gbar = readRDS ('8_logistic_g0_gbar.RDS')
The model formula was:
padult ~ (g0_s+gbar_s) * pfemale + vowel +
((g0_s+gbar_s) * pfemale + vowel | subj) + (1|speaker)
Meaning that we predict the perception of adultness using two continuous predictors (g0_s, and gbar_s), and a bunch of intercept differences.